import Cookie from 'js-cookie';

const tokenKey = 'yy-token';

// 设置token
export const setToken = (token: string) => {
  Cookie.set(tokenKey, token, { expires: 1 });
};

// 获取token
export const getToken = () => {
  return Cookie.get(tokenKey);
};
// 移除token
export const removeToken = () => {
  Cookie.remove(tokenKey);
};

export const hasAdminRole = (roles: string | string[]) => {
  if (!roles) return false;
  if (typeof roles === 'string') {
    return roles === 'admin';
  }
  return roles.includes('admin');
};
